import cv2

capture = cv2.VideoCapture(0, cv2.CAP_DSHOW)
while capture.isOpened():
    retval, img = capture.read()
    cv2.imshow('video', img)
    key = cv2.waitKey(1)
    # 按下空格键退出
    if key == 32:
        break

capture.release()
cv2.destroyAllWindows()
